/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.comfacauca.xmlc2.servlet;

import com.comfacauca.xmlc2.dao.ProyectosDAO;
import com.comfacauca.xmlc2.entidades.Acciones;
import com.comfacauca.xmlc2.entidades.Avance;
import com.comfacauca.xmlc2.entidades.Motivo;
import com.comfacauca.xmlc2.entidades.Requerimiento;
import com.comfacauca.xmlc2.entidades.Responsable;
import com.comfacauca.xmlc2.servicio.ProyectosI;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author sarita
 */
public class AvanceServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    ProyectosI proyectosI = new ProyectosDAO();
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        Avance avance = new Avance();
        
        avance.setId(0);
        avance.setFecha(new Date());
        avance.setValor(Integer.parseInt(request.getParameter("avance")));        
        Requerimiento requerimiento = new Requerimiento();
        requerimiento.setId(Integer.parseInt(request.getParameter("id")));        
        avance.setIdRequerimiento(requerimiento);        
        HttpSession session = request.getSession();
        Integer idautor = (Integer) session.getAttribute("id");
        Responsable autor = new Responsable(idautor);        
        avance.setIdAutor(autor);
        avance.setTiempo(Integer.parseInt(request.getParameter("tiempo")));
        
        proyectosI.setAvance(avance);
        
        Acciones acciones = new Acciones();
        acciones.setId(0);
        acciones.setFecha(new Date());
        acciones.setIdComentario(0);
        acciones.setIdAutor(autor);
        acciones.setIdRequerimiento(requerimiento);
        acciones.setMensaje("Actualizó el avance");
        acciones.setTipoAccion(0);
        
        Motivo motivo = new Motivo();
        motivo.setId(6);
        acciones.setIdMotivo(motivo);
        
        proyectosI.setAcciones(acciones);
        
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
